﻿using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;

namespace Smile.Xaml.Converter
{
    /// <summary>Boolean to visibility converter.</summary>
    public class BooleanToVisibilityConverter : IValueConverter
    {
        // @Public
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            bool givenValue = false;
            if (value is bool)
            {
                givenValue = (bool)value;
            }

            if (parameter != null && parameter is string && (string)parameter == "Inverse")
            {
                givenValue = !givenValue;
            }

            if (givenValue)
            {
                return Visibility.Visible;
            }
            else
            {
                return Visibility.Collapsed;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            return ((value is Visibility) && ((Visibility)value == Visibility.Visible));
        }
    }
}
